<template>
  <div class="app-container calendar-list-container">
    <div v-if="!opShow">
      <buttons :showQuery="false" :showBack="true"></buttons>
      <grid :columns="columns" :multi="false" :url="queryUrl" ref="mainGrid" height="auto" diffHeight="125" @change="rowCilck" :queryEntity="queryEntity" :permissions="permissions"
        :pagination="false" @edit="doEdit">
      </grid>
    </div>
  </div>
</template>

<script>
import request from '@/router/axios'
import url from '@/const/apiURL'
import grid from '@/components/Grid'
import buttons from '@/components/Buttons'
import { Message, MessageBox } from 'element-ui'
import { mapGetters } from 'vuex'
import { YesOrNoFormatter, PurchaseOrderStatusFormatter } from '@/const/dict'
import search from '@/components/Search'
import { colunms } from '@/const/colunms'
import { dict } from '@/const/dict'
import { queryField } from '@/const/query'
import { bgColor } from '@/const/bgColor'

export default {
  components: { grid, buttons, search },
  data () {
    return {
      queryUrl: url.PURCHASE_GOODS_LIST1_URL,
      disabled: true,
      opShow: false,
      businessOrderNo: '',
      queryEntity: { key: 'key' },
      columns: [
        { label: this.global.modelName, width: 120, prop: 'goodsName', align: 'left' },
        { label: this.global.modelProp, width: 100, prop: 'modelProp', align: 'left' },
        { label: '物料名称', width: 180, prop: 'materialName', align: 'left' },
        { label: '物料类型', width: 100, prop: 'materialTypeName', align: 'center' },
        { label: '单位', width: 80, prop: 'unit', align: 'center' },
        { label: '单价', width: 120, prop: 'price', align: 'center', template: 'edit', type: 'number' },
        { label: '数量', width: 120, prop: 'quantity', align: 'center', template: 'edit', type: 'number' },
        { label: '操作', width: 100, prop: 'op', align: 'center', template: 'op', opList: [{ name: '更新价格', clickName: 'edit', auth: 'yes' }] }
      ],
      btnList: [

      ],
      queryList: [

      ]
    }
  },
  created () {
    this.queryEntity.orderNo = this.$route.query.orderNo
  },
  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    doQuery (text) {
      this.$refs['mainGrid'].doQuery(text)
    },
    rowCilck (row) {
      this.disabled = row.length == 0
    },
    doBack () {
      this.$router.go(-1)
    },
    doEdit (row) {
      MessageBox.prompt('', '请输入单价', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((data) => {
        this.priceOp(row.code, Number(data.value)).then(result => {
          if (result) {
            this.doQuery()
          }
        })
      })
    },
    priceOp (code, price) {
      return request({
        url: url.PURCHASE_GOODS_PRICE_URL,
        method: 'post',
        data: { code, price }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
